#pragma once

#include <GLFW/glfw3.h>
#include "SourceCode/Base/Window.h"
#include "SourceCode/Renderer/GraphicsContext.h"

namespace Hazal
{
	/// <summary>
	/// 基于Windows平台的窗口类
	/// </summary>
	class CWindowsWindow : public CWindow
	{
	public:
		CWindowsWindow(const SWindowProps& props);

		virtual ~CWindowsWindow();

	public:
		void OnUpdate() override;

		inline unsigned int GetWidth() const override 
		{ 
			return m_Data.m_unWidth; 
		}
	
		inline unsigned int GetHeight() const override 
		{ 
			return m_Data.m_unHeight;
		}

		inline float GetFrameTime() override
		{
			float fCurrentTime = (float)glfwGetTime();
			float fTimeSpan = fCurrentTime - m_fLastFrameTime;

			m_fLastFrameTime = fCurrentTime;

			return fTimeSpan;
		}

	public:
		inline void SetEventCallback(const EventCallbackFn& callback) override
		{
			m_Data.m_eventCallback = callback;
		}

		void SetVSync(bool bEnabled) override;

		bool IsVSync() const override;

		void* GetNativeWindow() const override;

	private:
		virtual void Init(const SWindowProps& props);

		virtual void Shutdown();

	private:
		GLFWwindow* m_Window;

		/// <summary>
		/// 用于向GLFW窗口传递数据
		/// </summary>
		struct SWindowData
		{
			std::string m_strTitle;
			unsigned int m_unWidth;
			unsigned int m_unHeight;
			bool m_bVsync;

			EventCallbackFn m_eventCallback;
		};

		float m_fLastFrameTime;	///< 上一帧时间

		SWindowData m_Data;	///< 窗口对象包含数据

		CGraphicsContext* m_pContext; /// 上下文对象
	};
}